package net.tngou.c4j.ik;

public  class TnLexeme {
	   
    //词元的相对起始位置

    private int begin;
    //词元的长度

    private int length;
    //词元文本

    private String lexemeText;
    //词元类型

    private int type;
    //类型    0 text  1 html


    public TnLexeme( int begin , int length,String lexemeText,int type){
	
		this.begin = begin;
		if(length < 0){
			throw new IllegalArgumentException("length < 0");
		}
		this.length = length;
		this.lexemeText=lexemeText;
		this.type=type;
		
	}
    



public int getBegin() {
	return begin;
}
/**

 * 获取词元在文本中的起始位置

 * @return int

 */
public int getBeginPosition(){
	return  begin;
}

public void setBegin(int begin) {
	this.begin = begin;
}

/**

 * 获取词元在文本中的结束位置

 * @return int

 */
public int getEndPosition(){
	return  begin + length;
}

/**

 * 获取词元的字符长度

 * @return int

 */
public int getLength(){
	return this.length;
}	

public void setLength(int length) {
	if(this.length < 0){
		throw new IllegalArgumentException("length < 0");
	}
	this.length = length;
}

/**

 * 获取词元的文本内容

 * @return String

 */
public String getLexemeText() {
	if(lexemeText == null){
		return "";
	}
	return lexemeText;
}

public void setLexemeText(String lexemeText) {
	if(lexemeText == null){
		this.lexemeText = "";
		this.length = 0;
	}else{
		this.lexemeText = lexemeText;
		this.length = lexemeText.length();
	}
}


public String toString(){
	StringBuffer strbuf = new StringBuffer();
	strbuf.append(this.getBeginPosition()).append("-").append(this.getEndPosition());
	strbuf.append(" : ").append(this.lexemeText).append("  \t");	
	return strbuf.toString();
}




public int getType() {
	return type;
}




public void setType(int type) {
	this.type = type;
}
}